package com.chaokang.controller;

import com.chaokang.dao.entity.CommonUserEntity;
import com.chaokang.service.CommonUserService;
import com.chaokang.util.SendSmsUtil;
import com.tencentcloudapi.sms.v20190711.models.SendStatus;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
public class CommonUserController {
    @Autowired
    private CommonUserService commonUserService;
    @PostMapping(value = "/service/getCommonUserByID",produces = MediaType.APPLICATION_JSON_VALUE)
    public CommonUserEntity getCommonUserByID(@RequestBody CommonUserEntity commonUserEntity){

        return commonUserService.getCommonUserByID(commonUserEntity.getId());
    }
    @PostMapping(value = "/service/getCommonUserByIphone",produces = MediaType.APPLICATION_JSON_VALUE)
    public CommonUserEntity getCommonUserByIPhone(@RequestBody CommonUserEntity commonUserEntity){
        return commonUserService.getCommonUserByIphone(commonUserEntity.getIphone());
    }
    @PostMapping(value = "/service/insertCommonUser",produces = MediaType.APPLICATION_JSON_VALUE)
    public int insertCommonUser(@RequestBody CommonUserEntity commonUserEntity){
        return commonUserService.insertCommonUser(commonUserEntity);
    }
    @PostMapping(value = "/service/sendVerifyCode",produces = MediaType.APPLICATION_JSON_VALUE)
    public SendStatus[] sendVerifyCode(@RequestBody CommonUserEntity commonUserEntity){

        return commonUserService.sendVerifyCode(commonUserEntity);
    }

    @PostMapping(value = "/service/loginCommonUser",produces = MediaType.APPLICATION_JSON_VALUE)
    public CommonUserEntity loginCommonUser(@RequestBody CommonUserEntity commonUserEntity){

        return commonUserService.logIn(commonUserEntity);
    }
    @PostMapping(value = "/service/loginCommonUserByVarifyCode",produces = MediaType.APPLICATION_JSON_VALUE)
    public boolean loginCommonUserByVerifyCode(@RequestBody CommonUserEntity commonUserEntity){
        return commonUserService.logInByVarifyCode(commonUserEntity);
    }
    @PostMapping(value = "/service/confirmCommonUserCode")
    public CommonUserEntity confirmCode(@RequestBody CommonUserEntity commonUserEntity){
        return commonUserService.confimVarifyCode(commonUserEntity);
    }
    @PostMapping(value = "/service/changeCommonUserPassword")
    public CommonUserEntity changePassword(@RequestBody CommonUserEntity commonUserEntity){
        return commonUserService.retrievePassword(commonUserEntity);
    }
    @PostMapping(value = "/service/registerCommonUser")
    public Integer registerCommonUser(@RequestBody CommonUserEntity commonUserEntity){
        return commonUserService.registerCommonUser(commonUserEntity);
    }
}